#!/usr/bin/env bash
haszookeeper=$(ps aux|grep zookeeper|grep -v grep|wc -l)
if [ "" -le 1 ]; then
echo "没有安装zookeeper 请先安装zookeeper再进行kafka安装"
    exit -1
fi
wget -c http://apache.panu.it/kafka/2.3.0/kafka_2.11-2.3.0.tgz
tar -xvf kafka_2.11-2.3.0.tgz
 mv kafka_2.11-2.3.0 /usr/local/kafka
ln -s /usr/local/kafka/bin/* /usr/local/bin/
# 按照默认的配置来
servicefile=/usr/lib/systemd/system/kafka.service
if [ ! -f "$servicefile" ]; then
  cat >$servicefile<<EOF
[Unit]
Description=Zookeeper Service
After=syslog.target

[Service]
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh  /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
SuccessExitStatus=143
KillMode=process
Restart=on-failure
RestartSec=42s


[Install]
WantedBy=multi-user.target

EOF
systemctl daemon-reload

fi

firewall-cmd --zone=public --permanent --add-port=9092/tcp
firewall-cmd --reload